package java基础.array;

/**
 * @author IT_Jay
 * @date 2022/1/17 17:53
 */

public class arrayDemo04 {
    public static void main(String[] args) {
        int[] arrays = {1, 2, 3, 4, 5};
        //增强for循环，jdk1.5后，无下标的
        for (int array : arrays) {
            System.out.println(array);
        }

        printArray(arrays);
        System.out.println();
        int[] reverse = reverse(arrays);
        printArray(reverse);
    }

    //定义打印数组元素的方法
    public static void printArray(int[] arrays) {
        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays[i] + "\t");
        }
    }

    //定义一个反转数组的方法
    public static int[] reverse(int[] arrays) {
        int[] result = new int[arrays.length];
        int j = result.length - 1;
        for (int i = 0; i < arrays.length; i++) {
            result[j] = arrays[i];
            j--;
        }

        return result;
    }
}
